package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.TokenVisitor;

public class CONDICIONFactory extends AbstractTokenVisitorFactory {

	private static CONDICIONFactory INSTANCE;
	
	private CONDICION1Factory condicion1Factory;
	private CONDICION2Factory condicion2Factory;
	private CONDICION3Factory condicion3Factory;
	private CONDICION4Factory condicion4Factory;
	private CONDICION5Factory condicion5Factory;

	
	public static CONDICIONFactory getInstance() throws Exception {
		if(INSTANCE==null) INSTANCE = new CONDICIONFactory();
		return INSTANCE;
	}
	
	private Initializer initializer = new Initializer() {
		
		@Override
		public void init() throws Exception {
			initializer = NoOperationInitializer.getInstance();
			condicion1Factory = CONDICION1Factory.getInstance();
			condicion2Factory = CONDICION2Factory.getInstance();
			condicion3Factory = CONDICION3Factory.getInstance();
			condicion4Factory = CONDICION4Factory.getInstance();
			condicion5Factory = CONDICION5Factory.getInstance();
		}			

	};
	
	private CONDICIONFactory() throws Exception {

	}
	
	@Override
	public TokenVisitor makeChainedVisitor(final TokenVisitor siguiente) throws Exception {
		initializer.init();

		return condicion1Factory.makeChainedVisitor(condicion2Factory.makeChainedVisitor(condicion3Factory.makeChainedVisitor(condicion4Factory.makeChainedVisitor(condicion5Factory.makeChainedVisitor(siguiente)))));
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		initializer.init();

		return condicion1Factory.makeChainedVisitor(condicion2Factory.makeChainedVisitor(condicion3Factory.makeChainedVisitor(condicion4Factory.makeChainedVisitor(condicion5Factory.makeVisitor()))));
	}
	
	
}
